<?php
class BizbridgeAction extends BizbaseAction{
	function _initialize(){
	}

    //输出微博编写框
    function index(){
        $this->display();
    }
    function showOneInfo(){
    	$uid = h($_GET['uid']);
    	$strType = 'original';

	   if( is_string($uid) ){
	   		$domainuser = M('user')->where("domain='".$uid."'")->find();
	   		if($domainuser){
	   			$uid = $domainuser['uid'];
	   			$this->assign('uid',$uid);
	   		}
	   }

   	   $userInfo = M('user')->where('uid='.$uid)->find();
   	   if(!$userInfo){
		   	$this->output['result'] = 0;
			$this->output['message'] = '用户不存在或提交了错误参数';
			$this->outputJson();
	   }

//从个人ID获得公司ID
		$bizUserDao = D('CorpUser','corp');
		$corpId = $bizUserDao->getCorpIdFromUserId($uid);
//从公司Id获得公司信息
		$corpInfo = array(
				'corpId'=>'0',
				'corpName'=> '',
				'corpTitle'=> '',
				);
		if($corpId){
			$map = array("corpId","corpName","corpTitle");
			$BizCorpDao = D('BizCorp');
			$corpInfo = $BizCorpDao->getCorpInfoFromId($corpId,'zh-cn',$map);
		}
		$userInfo['corp'] = $corpInfo;

		$this->assign('userinfo',$userInfo);

		$followInfo = getUserFollow( $uid );
		$data['followstate'] 	=  D('Follow','weibo')->getState( $this->mid , $uid , 0 );
		$data['isBlackList']    = isBlackList($this->mid,$uid);
		$data['privacy']        = D('UserPrivacy','home')->getPrivacy($this->mid,$uid);
		$data['spaceCount']['miniblog']   = M('weibo')->where('uid='.$uid)->count();
		$data['spaceCount']['following']  = $followInfo['following'];
		$data['spaceCount']['follower']   = $followInfo['follower'];
		$this->assign( $data );

        $data['list']['data'] =  D('Operate','weibo')->getLast( $uid , $strType,1);

		$data['user'] =  M('User')->where('uid='.$uid)->find();
        $data['type'] = $strType;
        $this->assign( $data );
		$this->output['rehtml'] = $this->fetch();
		$this->output['result'] = 1;
		$this->outputJson();

        //$this->display();
    }

    //检测
    function checkNew(){
		$this->output['result'] = 1;
		if($this->checkLogin()){
			$this->output['newNotify'] = x('Notify')->getCount($this->mid);
		}
		$this->outputJson();
    }
	//获取一些人的信息
    function getUserInfo(){
    	if(empty($_GET['userId'])){
    		$this->output['result'] = 0;
			$this->output['userInfo'] = '';
			$this->outputJson();
    	}
    	if(empty($_GET['fieldmap'])){
  			$fieldmap = array('uid','email','uname','sex');
    	}else{
    		$fieldmap = $_GET['fieldmap'];
    	}
		$userInfo = M('User')->field($fieldmap)->where('uid IN ('.$_GET['userId'].')')->findAll();

		if(empty($userInfo)){
			$this->output['userInfo'] = '';
			$this->output['result'] = 0;
			$this->outputJson();
		}
		if(empty($_GET['avatar'])){
			$avatar = 'm';
		}
		$types = array('m'=>'middle.jpg', 's'=>'small.jpg', 'b'=>'big.jpg');
		foreach($userInfo as $v){
			$userInfolist[$v['uid']] = $v;
			$userface = SITE_PATH.'/data/uploads/avatar/'.$v['uid'].'/'.$types[$avatar];
			if(is_file($userface)){
				$userInfolist[$v['uid']]['avatar'] = 1;
			}else{
				$userInfolist[$v['uid']]['avatar'] = 0;
			}
		}

		$this->output['userInfo'] = $userInfolist;
		$this->output['result'] = 1;
		$this->outputJson();
    }
    //首页显示最新微博
    function showNewWeibo(){
   			//	die('showNewWeibo');
    return $this->fetch();
    }
    //首页显示有趣的人
    function showInteresting(){
   				//die('showInteresting');
       return $this->fetch();
    }
	function showSnsBox(){
		$this->output['Box'] = '';
		$wantBox = $_GET['wantBox'];
		if(empty($wantBox)){
			$this->output['result'] = 0;
			$this->outputJson();
		}
		$wantBoxArr = explode(',',$wantBox);//implode变成串
		foreach($wantBoxArr as $aWant){
			$want =  explode('|',$aWant);//implode变成串
			$thismetods = (get_class_methods($this));

			if(in_array($want[1],$thismetods)){
die($this->{$want[1]}());
				$this->output['Box'][$want[0]] = $this->{$want[1]}();
				die('In');

			}else{
				die('No');
			}
		}

		$this->output['result'] = 1;
		$this->outputJson();
    }
}
?>